<template>
  <div class="market-main-page">
    <!-- 用户信息栏 -->
    <UserInfoBar />

    <!-- 市场入口卡片 -->
    <div class="market-entrances">
      <!-- 道具市场入口 -->
      <div class="market-entrance" @click="navigateToItems">
        <div class="entrance-icon items-icon">
          <span class="icon-emoji">💊</span>
        </div>
        <div class="entrance-content">
          <div class="entrance-title">道具市场</div>
          <div class="entrance-subtitle">丹药、材料、消耗品</div>
          <div class="entrance-stats">
            <span class="stat-text">{{ itemsMarketCount }}件在售</span>
          </div>
        </div>
        <div class="entrance-arrow">→</div>
      </div>

      <!-- 装备市场入口 -->
      <div class="market-entrance" @click="navigateToEquipment">
        <div class="entrance-icon equipment-icon">
          <span class="icon-emoji">⚔️</span>
        </div>
        <div class="entrance-content">
          <div class="entrance-title">装备市场</div>
          <div class="entrance-subtitle">武器、防具、饰品</div>
          <div class="entrance-stats">
            <span class="stat-text">{{ equipmentMarketCount }}件在售</span>
          </div>
        </div>
        <div class="entrance-arrow">→</div>
      </div>
    </div>

    <!-- 快捷功能 -->
    <div class="quick-actions">
      <div class="action-title">快捷功能</div>
      <div class="action-grid">
        <div class="action-item" @click="showMyItems">
          <div class="action-icon">📦</div>
          <div class="action-label">我的商品</div>
        </div>
        <div class="action-item" @click="showMyOrders">
          <div class="action-icon">📋</div>
          <div class="action-label">交易记录</div>
        </div>
        <div class="action-item" @click="showFavorites">
          <div class="action-icon">⭐</div>
          <div class="action-label">我的收藏</div>
        </div>
        <div class="action-item" @click="showHelp">
          <div class="action-icon">❓</div>
          <div class="action-label">市场帮助</div>
        </div>
      </div>
    </div>

    <!-- 全局底部导航栏 -->
    <CustomTabBar />
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import api from '@/api'

export default {
  name: 'MarketMainPage',
  data() {
    return {
      itemsMarketCount: 0,
      equipmentMarketCount: 0,
      loading: false
    }
  },
  mounted() {
    this.loadMarketStats()
  },
  methods: {
    // 跳转到道具市场
    navigateToItems() {
      uni.navigateTo({
        url: '/pages/market/items'
      })
    },
    
    // 跳转到装备市场
    navigateToEquipment() {
      uni.navigateTo({
        url: '/pages/market/equipment'
      })
    },
    
    // 加载市场统计信息
    async loadMarketStats() {
      this.loading = true
      try {
        // 获取道具市场数量
        const itemsResponse = await api.post('/store/info', { type: 'items' })
        if (itemsResponse && itemsResponse.code === 1) {
          this.itemsMarketCount = itemsResponse.data?.count || 0
        }
        
        // 获取装备市场数量
        const equipmentResponse = await api.post('/store/info', { type: 'equipment' })
        if (equipmentResponse && equipmentResponse.code === 1) {
          this.equipmentMarketCount = equipmentResponse.data?.count || 0
        }
      } catch (error) {
        console.error('加载市场统计失败:', error)
      } finally {
        this.loading = false
      }
    },
    
    // 显示我的商品
    showMyItems() {
      uni.showToast({ title: '功能开发中', icon: 'none' })
    },
    
    // 显示交易记录
    showMyOrders() {
      uni.showToast({ title: '功能开发中', icon: 'none' })
    },
    
    // 显示收藏
    showFavorites() {
      uni.showToast({ title: '功能开发中', icon: 'none' })
    },
    
    // 显示帮助
    showHelp() {
      uni.showToast({ title: '功能开发中', icon: 'none' })
    }
  }
}
</script>

<style scoped>
/* ========== 武侠风格市场主页 ========== */
.market-main-page {
  min-height: 100vh;
  background: linear-gradient(180deg, #e8dcc4 0%, #d4c4a8 100%);
  padding: 0 15px 80px 15px;
  font-family: "STSong", "Noto Serif SC", serif;
}

/* ========== 市场入口卡片 ========== */
.market-entrances {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-bottom: 30px;
}

.market-entrance {
  background: rgba(255, 255, 255, 0.98);
  border: 3px solid #c4a57b;
  border-radius: 16px;
  padding: 25px;
  display: flex;
  align-items: center;
  gap: 20px;
  box-shadow: 0 5px 15px rgba(139, 111, 71, 0.25);
  transition: all 0.3s ease;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.market-entrance::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, #d4af37 0%, #ffd700 50%, #d4af37 100%);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.market-entrance:hover::before {
  opacity: 1;
}

.market-entrance:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 25px rgba(139, 111, 71, 0.35);
  border-color: #8b6f47;
}

.market-entrance:active {
  transform: translateY(-1px);
}

.entrance-icon {
  width: 80px;
  height: 80px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  border: 3px solid;
  transition: all 0.3s ease;
}

.market-entrance:hover .entrance-icon {
  transform: scale(1.05);
}

.items-icon {
  background: linear-gradient(135deg, #6b8e67 0%, #5a7a56 100%);
  border-color: #4a6a46;
}

.equipment-icon {
  background: linear-gradient(135deg, #d4af37 0%, #b8951f 100%);
  border-color: #9a7a15;
}

.icon-emoji {
  font-size: 40px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.entrance-content {
  flex: 1;
}

.entrance-title {
  font-size: 22px;
  font-weight: 700;
  color: #4a3c2a;
  margin-bottom: 8px;
  letter-spacing: 2px;
  text-shadow: 0 1px 2px rgba(139, 111, 71, 0.1);
}

.entrance-subtitle {
  font-size: 14px;
  color: #8b6f47;
  margin-bottom: 10px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.entrance-stats {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stat-text {
  font-size: 13px;
  color: #6b4f3b;
  font-weight: 700;
  padding: 4px 12px;
  background: rgba(212, 175, 55, 0.15);
  border: 1px solid #d4af37;
  border-radius: 12px;
}

.entrance-arrow {
  font-size: 28px;
  color: #8b6f47;
  font-weight: bold;
  flex-shrink: 0;
  transition: all 0.3s ease;
}

.market-entrance:hover .entrance-arrow {
  transform: translateX(4px);
  color: #6b4f3b;
}

/* ========== 快捷功能 ========== */
.quick-actions {
  background: rgba(255, 255, 255, 0.98);
  border: 3px solid #c4a57b;
  border-radius: 16px;
  padding: 25px;
  box-shadow: 0 5px 15px rgba(139, 111, 71, 0.25);
}

.action-title {
  font-size: 18px;
  font-weight: 700;
  color: #4a3c2a;
  margin-bottom: 18px;
  letter-spacing: 1px;
  padding-bottom: 12px;
  border-bottom: 2px solid #e8dcc4;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 15px;
}

.action-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 18px 12px;
  background: rgba(139, 111, 71, 0.05);
  border: 2px solid #d8c7a3;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.action-item:hover {
  background: rgba(139, 111, 71, 0.12);
  border-color: #c4a57b;
  transform: translateY(-3px);
  box-shadow: 0 4px 12px rgba(139, 111, 71, 0.2);
}

.action-item:active {
  transform: translateY(-1px);
}

.action-icon {
  font-size: 32px;
  margin-bottom: 4px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.action-label {
  font-size: 13px;
  color: #4a3c2a;
  text-align: center;
  font-weight: 700;
  letter-spacing: 0.5px;
}

/* ========== 响应式设计 ========== */
@media (max-width: 768px) {
  .market-entrance {
    padding: 20px;
  }
  
  .entrance-icon {
    width: 70px;
    height: 70px;
  }
  
  .icon-emoji {
    font-size: 35px;
  }
  
  .entrance-title {
    font-size: 20px;
  }
  
  .action-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .market-entrances {
    gap: 15px;
  }
  
  .market-entrance {
    padding: 18px;
    gap: 15px;
  }
  
  .entrance-icon {
    width: 65px;
    height: 65px;
  }
  
  .icon-emoji {
    font-size: 32px;
  }
  
  .entrance-title {
    font-size: 18px;
  }
  
  .entrance-subtitle {
    font-size: 13px;
  }
  
  .action-title {
    font-size: 16px;
  }
  
  .action-item {
    padding: 15px 10px;
  }
  
  .action-icon {
    font-size: 28px;
  }
  
  .action-label {
    font-size: 12px;
  }
}
</style>
